<!--
 * @Description: 交工数据标准
 * @Autor: yjx
 * @Date: 2021-11-19 09:54:54
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-01-04 16:41:17
-->
<template>
    <div class="due_data_standard">
        <div v-if="indexList.includes(index) && config.specificationId">
            <div class="top">
                <div class="btn">
                    <el-button size="mini" class="bottom_all"  @click="handleSave">保 存</el-button>
                </div>
            </div>

            <div class="content">
                <Table :tableConfig="tableConfig" :tableData="tableData" />
            </div>
        </div>
        <div v-else class="text">暂无数据</div>
    </div>
</template>
<script>
import Table from '@/views/platform/ICPS/smart/schedul/components/BlockTable.vue'
import { saveOrUpdate3, queryStand } from "@/api/qualityTemplate"

export default {
    components: {
        Table,
    },
    props: {
        index: {
            type: String,
            default: ()=>''
        },
        config: {
            type: Object,
            default: ()=>{}
        }
    },
    data() {
        return {
            tableConfig: [
                {label: '检验项目', prop: 'name'},
                {label: '下限值', prop: 'min', render:({row})=>(row.type === 'input' ? <el-input v-model={row.min} type="number" placeholder="请输入" /> : '/')},
                {label: '上限值', prop: 'max', render:({row})=>(row.type === 'input' ? <el-input v-model={row.max} type="number" placeholder="请输入" /> : '/')},
                {label: '下拉数据标准', prop: 'select', render:({row})=>(
                    row.type === 'select' ? 
                    <el-select v-model={row.select} value-key='value'>
                        {
                            row.options.map(item=>(<el-option value={item} label={item.label}></el-option>))
                        }
                    </el-select>
                    :
                    '/'
                )}
            ],
            tableData: [],
            indexList: [],
        }
    },
    watch: {
        index(newVal) {
            const obj = {
                '1': [ // 水泥
                    {type: 'input', name: '稠度标准', min: '', max: ''},
                    {type: 'input', name: '细度 0.08mm筛余（%）', min: '', max: ''},
                    {type: 'select', name: '安定性', select: '', options: [{ value: 0, label: '合格' }, { value: 1, label: '不合格'}]},
                    {type: 'input', name: '凝结时间-初凝时间', min: '', max: ''},
                    {type: 'input', name: '凝结时间-终凝时间', min: '', max: ''},
                    {type: 'input', name: '抗折强度 （MPa）-3d-单个值1', min: '', max: ''},
                    {type: 'input', name: '抗折强度 （MPa）-3d-单个值2', min: '', max: ''},
                    {type: 'input', name: '抗折强度 （MPa）-3d-单个值3', min: '', max: ''},
                    {type: 'input', name: '抗折强度 （MPa）-28d-单个值1', min: '', max: ''},
                    {type: 'input', name: '抗折强度 （MPa）-28d-单个值2', min: '', max: ''},
                    {type: 'input', name: '抗折强度 （MPa）-28d-单个值3', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-3d-单个值1', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-3d-单个值2', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-3d-单个值3', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-3d-单个值4', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-3d-单个值5', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-3d-单个值6', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-28d-单个值1', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-28d-单个值2', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-28d-单个值3', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-28d-单个值4', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-28d-单个值5', min: '', max: ''},
                    {type: 'input', name: '抗压强度 （MPa）-28d-单个值6', min: '', max: ''},
                ],
                '5': [ // 砂
                    {type: 'input', name: '堆积密度-平均值（kg/m3）', min: '', max: ''},
                    {type: 'input', name: '表观密度-平均值（kg/m3）', min: '', max: ''},
                    {type: 'input', name: 'MB值（g/kg）', min: '', max: ''},
                    {type: 'input', name: '空隙率（%）', min: '', max: ''},
                    {type: 'input', name: '石粉含量（%）', min: '', max: ''},
                    {type: 'input', name: '泥块含量-平均值（%）', min: '', max: ''},
                    {type: 'input', name: '坚固性（质量损失）（%）', min: '', max: ''},
                    {type: 'input', name: '含水率（%）', min: '', max: ''},
                    {type: 'input', name: '吸水率（%）', min: '', max: ''},
                    {type: 'input', name: '有机物含量（比色法）', min: '', max: ''},
                    {type: 'input', name: '云母含量 （%）', min: '', max: ''},
                    {type: 'input', name: '轻物质含量 （%）', min: '', max: ''},
                    {type: 'input', name: '氯盐含量 （%） ', min: '', max: ''},
                    {type: 'input', name: '硫酸盐硫化物含量（%） ', min: '', max: ''},
                    {type: 'input', name: '筛分结果-9.50 (10.0)-分计筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-4.75 (5.00)-分计筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-2.36 (2.50)-分计筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-1.18 (1.25)-分计筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-0.60 (0.63)-分计筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-0.30 (0.315)-分计筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-0.15 (0.160)-分计筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-筛底-分计筛余（%）', min: '', max: ''},
                ],
                '6': [ // 石
                    {type: 'input', name: '堆积密度（kg/m3）', min: '', max: ''},
                    {type: 'input', name: '表观密度（kg/m3）', min: '', max: ''},
                    {type: 'input', name: '紧密（kg/m3）', min: '', max: ''},
                    {type: 'input', name: '空隙率（%）', min: '', max: ''},
                    {type: 'input', name: '含泥量（%）', min: '', max: ''},
                    {type: 'input', name: '泥块含量（%）', min: '', max: ''},
                    {type: 'input', name: '压碎指标（%）', min: '', max: ''},
                    {type: 'input', name: '含水率（%）', min: '', max: ''},
                    {type: 'input', name: '吸水率（%）', min: '', max: ''},
                    {type: 'input', name: '针、片状颗粒含量（%）', min: '', max: ''},
                    {type: 'input', name: '有机物含量', min: '', max: ''},
                    {type: 'input', name: '坚固性（%）', min: '', max: ''},
                    {type: 'input', name: '三氧化硫含量（%）', min: '', max: ''},
                    {type: 'input', name: '岩石抗压强度（MPa）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-90.0 (100.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-75.0 (80.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-63.0 (63.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-53.0 (50.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-37.5 (40.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-31.5 (31.5)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-26.5 (25.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-19.0 (20.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-16.0 (16.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-9.5 (10.0)-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-4.75 (5.0 )-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-2.36 (2.5 )-分级筛余（%）', min: '', max: ''},
                    {type: 'input', name: '筛分结果-筛底-分级筛余（%）', min: '', max: ''}
                ]
            }
            this.indexList = Object.keys(obj);
            this.tableData = obj[newVal]
        },
        config: {
            deep: true,
            handler: function(newVal) {
                const params = {
                    companyId: newVal.companyId,
                    nameId: newVal.nameId,
                    specificationId: newVal.specificationId,
                    type: 1
                }
                queryStand(params).then(res=>{
                    if(res && res.code === 1001 && res.data && res.data.content) {
                        this.tableData = JSON.parse(res.data.content)
                    }
                })
            }
        }
    },
    methods: {
        handleSave() { // 保存
            const params = {
                ...this.config,
                projectList: this.formatData(),
                content: JSON.stringify(this.tableData)
            }
            saveOrUpdate3(params).then(res=>{
                if(res && res.code === 1001) {
                    this.$message.success('保存成功')
                }
            })
        },
        formatData() { // 格式化表格数据，处理成后端需要的格式
            const arr = [];
            this.tableData.forEach((item, index)=>{
                if(item.type === 'select') {
                    arr.push({
                        checkProject: item.name,
                        checkProjectId: index,
                        dataType: 1, //数据类型：数据类型：1下拉框2数值范围3输入框
                        requirement: item.select ? item.select.value : '',
                        requirementValue: item.select ? item.select.label : '',
                        requirementCondition: JSON.stringify(item.options)
                    })
                }
                if(item.type === 'input') {
                    arr.push({
                        checkProject: item.name,
                        checkProjectId: index,
                        dataType: 2, //数据类型：数据类型：1下拉框2数值范围3输入框
                        lowerLimit: item.min,
                        upperLimit: item.max
                    })
                }
            })
            return arr
        },
    },
}
</script>
<style lang="scss" scoped>
.due_data_standard {
    box-sizing: border-box;
    width: 100%;
    padding: 20px;
    .top {
        display: flex;
        align-items: center;
        padding-bottom: 20px;
        .select {
            display: flex;
            align-items: center;
        }
    }
    .content {
        width: 100%;
        height: 430px;
        overflow: auto;

    }
    .text {
        width: 100%;
        height: 500px;
        color: #ccc;
        display: flex;
        justify-content: center;
        align-items: center;
    }
}
</style>


